﻿using System.Collections.Generic;

namespace FlashPay.Service.Impl.Sys
{
    using AutoMapper;
    using FlashPay.DAO.Interface;
    using FlashPay.DAO.Sys;
    using FlashPay.Entity.Response.Sys;
    using FlashPay.Service.Sys;
    using FlashPay.Entity.Response.Company;
    using FlashPay.Entity.Parameter;
    using FlashPay.Entity;
    using FlashPay.EF.Models;

    /// <summary>
    /// 系统配置业务实现
    /// </summary>
    public class SysServiceImpl : SysService
    {
        /// <summary>
        /// 系统配置接口
        /// </summary>
        private readonly SysConfigDao _sysConfigDao;

        /// <summary>
        /// 银行数据接口
        /// </summary>
        private readonly BankDao _bankDao;

        /// <summary>
        /// mapper
        /// </summary>
        private readonly IMapper _mapper;

        /// <summary>
        /// 
        /// </summary>
        /// <param name="sysConfigDao"></param>
        /// <param name="bankDao"></param>
        /// <param name="mapper"></param>
        public SysServiceImpl(SysConfigDao sysConfigDao,BankDao bankDao,IMapper mapper)
        {
            this._bankDao = bankDao;
            this._sysConfigDao = sysConfigDao;
            this._mapper = mapper;
        }

        /// <summary>
        /// 根据编号获取系统配置
        /// </summary>
        /// <param name="id">编号</param>
        /// <returns>菜单</returns>
        public SysConfigResponse Get(int configId,int companyId)
        {
            var response = new SysConfigResponse();

            var sysConfig = _sysConfigDao.Get(configId);
            if (response != null) {
                response =_mapper.Map<SysConfigResponse>(sysConfig);
            }

            #region 公司列表
            var companys = _bankDao.GetCompany(companyId, 2);

            var companyResponse = new List<CompanyResponse>();
            foreach (var item in companys)
            {
                companyResponse.Add(new CompanyResponse()
                {
                    CompanyID = item.CompanyID,
                    CompanyName = item.CompanyName,
                });
            }
            response.CompanyResponse = companyResponse;
            #endregion

            return response;
        }

        /// <summary>
        /// 获取第三方接口列表
        /// </summary>
        /// <param name="id">编号</param>
        /// <returns>菜单</returns>
        public PagedList<PaymentInterfaceNew> GetPayMentInterfaceList(PaymentInterfaceQuery query) {
            return _sysConfigDao.GetPayMentInterfaceList(query);
        }

    }
}
